package com.insigma.cisco.itc.tms.teammanagement.action;

import org.apache.struts2.json.annotations.JSON;

import com.insigma.cisco.itc.tms.common.action.BaseAction;
import com.insigma.cisco.itc.tms.common.domain.User;
import com.insigma.cisco.itc.tms.teammanagement.service.RegisterService;

public class RegisterAction extends BaseAction {

	private static final long serialVersionUID = -2422245322357925318L;

	private String username;

	private String password;

	private String repeat_password;

	private String phone;

	private String name;

	private String team;

	private String email;

	private RegisterService registerService;

	private User user;

	private String isDublicapted;

	public String getIsDublicapted() {
		return isDublicapted;
	}

	public void setIsDublicapted(String isDublicapted) {
		this.isDublicapted = isDublicapted;
	}

	@JSON(serialize = false)
	public RegisterService getRegisterService() {
		return registerService;
	}

	public void setRegisterService(RegisterService registerService) {
		this.registerService = registerService;
	}

	@JSON(serialize = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTeam() {
		return team;
	}

	public void setTeam(String team) {
		this.team = team;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getRepeat_password() {
		return repeat_password;
	}

	public void setRepeat_password(String repeatPassword) {
		repeat_password = repeatPassword;
	}

	public String register() {
		user = new User();
		user.setUsername(username);
		user.setEmail(email);
		user.setLevel(1);
		user.setName(name);
		user.setPassword(password);
		user.setPhone(phone);
		user.setTeam(team);
		registerService.registeUser(user);
		return SUCCESS;
	}

	public String update() {
		User user = (User) session.get("user");
		user.setEmail(email);
		user.setLevel(1);
		user.setName(name);
		user.setPassword(password);
		user.setPhone(phone);
		user.setTeam(team);
		registerService.updateUser(user);
		return SUCCESS;
	}

	public String isDublipcated() {
		if (registerService.isDublipcated(username))
			this.setIsDublicapted("true");
		else {
			this.setIsDublicapted("false");
		}
		return JSON;

	}

	public String showRegister() {
		return REGISTER;
	}

	public String showUpdate() {
		if (session.get("user") == null) {
			return LOGIN;
		} else {
			return UPDATE;
		}
	}
}
